package com.wenhai.spring.annotation;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;

/**
 * {@link Profile} 示例
 *
 * @author wenhai
 * @date 2020/9/10
 * @see Environment#getActiveProfiles()
 */
@Configuration
public class ProfileDemo {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProfileDemo.class);
//        ConfigurableEnvironment environment = context.getEnvironment();
//        environment.setDefaultProfiles("odd");
//        context.register(ProfileDemo.class);
//        context.refresh();
        Integer number = context.getBean("number", Integer.class);
        System.out.println(number);
        context.close();
    }

    @Bean("number")
    @Profile("odd")
    public Integer odd() {
        return 1;
    }

    @Bean("number")
    @Profile("even")
    public Integer even() {
        return 2;
    }
}
